function scaledSADEfficiency = sad2D(signal, template)
%SAD2D performs 2D sum of absolute differences algoritm for given template
%and signal
signalSize = size(signal);
templateSize = size(template);
windowsNumber = signalSize - templateSize + 1;
sadEfficiency = zeros(windowsNumber);
for i = 1:windowsNumber(1)
    for j = 1:windowsNumber(2)
        windowSignal = signal(i:i + templateSize(1) - 1, j:j + templateSize(2) - 1);
        absDiff = abs(windowSignal - template);
        sadEfficiency(i, j) = sum(sum(absDiff));
    end
end
sadEfficiency = sadEfficiency / max(max(sadEfficiency));
sadMean = mean(mean(sadEfficiency));
scaledSADEfficiency = scale2DEffectogram(sadEfficiency, templateSize, signalSize, sadMean);
end
